package com.ytd.common.util;

import android.os.Handler;
import android.os.Looper;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 线程工具类
 *
 * @author gaoguanchao
 * @since 2023/3/28
 */
public class ThreadUtil {
    private static ExecutorService pool = Executors.newCachedThreadPool();
    private static ExecutorService filePool = Executors.newSingleThreadExecutor();
    private static Handler sHandler = new Handler(Looper.getMainLooper());

    public static void execute(Runnable runnable) {
        pool.execute(runnable);
    }

    public static void executeFile(Runnable runnable) {
        filePool.execute(runnable);
    }

    public static void executeMain(Runnable runnable) {
        sHandler.post(runnable);
    }

    public static void executeMainDelayed(Runnable runnable, long delayMillis) {
        sHandler.postDelayed(runnable, delayMillis);
    }

    public static void removeMainRunnable(Runnable runnable) {
        sHandler.removeCallbacks(runnable);
    }
}
